package com.github.yoojia.flow.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 陈哈哈 yoojiachen@gmail.com
 */
public class Invoker {

    private static final Logger LOGGER = LoggerFactory.getLogger("Invoker");

    private Invoker() {

    }

    public static <T> T catchInvoke(ThrowFunction<T> function, String error) {
        try {
            return function.accept();
        } catch (Throwable e) {
            LOGGER.error(error, e);
            return null;
        }
    }

    public interface ThrowFunction<R> {
        R accept() throws Throwable;
    }
}
